package com.bawei.yuekao.adapter;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

/**
 * @Author : yaotianxue
 * @Time : On 2023/7/8 08:16
 * @Description : MyFragmentPagerAdapter
 */
public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> mList;//fragment
    private List<String> titles;//标题

    public MyFragmentPagerAdapter(@NonNull FragmentManager fm, int behavior, List<Fragment> list, List<String> titles) {
        super(fm, behavior);
        mList = list;
        this.titles = titles;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return mList.get(position);
    }

    @Override
    public int getCount() {
        return mList.size();
    }
    //手动重写：返回ttablayout每个itle标题
    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }
}
